﻿<Page
    x:Class="TtsBTUniversalDemo.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TtsBTUniversalDemo"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:behaviors="using:WpWinNl.Behaviors"
    xmlns:converters="using:WpWinNl.Converters"
    xmlns:viewmodels="using:TtsBTUniversalDemo.Viewmodels"
    mc:Ignorable="d">

  <Page.Resources>
    <converters:VisibilityConverter x:Key="VisibilityConverter"/>
    <viewmodels:NfcConnectViewModel x:Key="MainViewModel" />
    <converters:BoolInvertConverter x:Key="BooleanInvertConvertor" />
    <behaviors:HideWhenCollectionEmptyBehavior x:Key="HideWhenCollectionEmptyBehavior" />
    <DataTemplate x:Key="NormalContactTemplate">
      <TextBlock TextWrapping="Wrap" Text="{Binding DisplayName}"/>
    </DataTemplate>
    <DataTemplate x:Key="FullScreenContactTemplate">
      <TextBlock TextWrapping="Wrap" Text="{Binding DisplayName}" FontSize="48"/>
    </DataTemplate>
    <Style x:Key="MyListboxStyle" TargetType="ListBox">
      <Setter Property="Foreground" Value="{ThemeResource ListBoxForegroundThemeBrush}"/>
      <Setter Property="Background" Value="{ThemeResource ListBoxBackgroundThemeBrush}"/>
      <Setter Property="BorderBrush" Value="{ThemeResource ListBoxBorderThemeBrush}"/>
      <Setter Property="BorderThickness" Value="{ThemeResource ListBoxBorderThemeThickness}"/>
      <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
      <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
      <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled"/>
      <Setter Property="ScrollViewer.IsHorizontalRailEnabled" Value="True"/>
      <Setter Property="ScrollViewer.VerticalScrollMode" Value="Enabled"/>
      <Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="True"/>
      <Setter Property="ScrollViewer.ZoomMode" Value="Disabled"/>
      <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False"/>
      <Setter Property="ScrollViewer.BringIntoViewOnFocusChange" Value="True"/>
      <Setter Property="IsTabStop" Value="False"/>
      <Setter Property="TabNavigation" Value="Once"/>
      <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
      <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
      <Setter Property="ItemsPanel">
        <Setter.Value>
          <ItemsPanelTemplate>
            <VirtualizingStackPanel/>
          </ItemsPanelTemplate>
        </Setter.Value>
      </Setter>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="ListBox">
            <Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
              <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                  <VisualState x:Name="Normal"/>
                  <VisualState x:Name="Disabled">
                    <Storyboard>
                      <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="LayoutRoot">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
                      </ObjectAnimationUsingKeyFrames>
                      <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="LayoutRoot">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ListBoxDisabledForegroundThemeBrush}"/>
                      </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                  </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="FocusStates">
                  <VisualState x:Name="Focused">

                  </VisualState>
                  <VisualState x:Name="Unfocused"/>
                </VisualStateGroup>
              </VisualStateManager.VisualStateGroups>
              <ScrollViewer x:Name="ScrollViewer" AutomationProperties.AccessibilityView="Raw" BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}" HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" Padding="{TemplateBinding Padding}" TabNavigation="{TemplateBinding TabNavigation}" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}">
                <ItemsPresenter/>
              </ScrollViewer>
            </Border>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

  </Page.Resources>

  <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
    DataContext="{StaticResource MainViewModel}">
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
      <TextBlock Text="TAP TO CONNECT"  Margin="12,0" FontSize="29.333"/>
      <TextBlock Text="demo" Margin="9,-7,0,0" FontSize="21.333" />
    </StackPanel>

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
      <Grid.RowDefinitions>
        <RowDefinition Height="461*"/>
        <RowDefinition Height="146*"/>
      </Grid.RowDefinitions>
      <!-- Connect panel-->
      <Grid x:Name="ConnectGrid" Margin="0,0,0,76" Grid.RowSpan="2" Visibility="{Binding IsConnecting, Converter={StaticResource VisibilityConverter}}" >
        <Grid.RowDefinitions>
          <RowDefinition Height="*"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Button Content="Connect" HorizontalAlignment="Center" VerticalAlignment="Top"  IsEnabled="{Binding CanInitiateConnect}" Command="{Binding StartCommmand}" Grid.Row="1"/>
        <Grid Grid.Row="2">
          <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
          </Grid.RowDefinitions>

          <RadioButton Content="tap+send" IsChecked="{Binding UseBlueTooth, Converter={StaticResource BooleanInvertConvertor}, Mode=TwoWay}"  IsEnabled="{Binding CanInitiateConnect, Mode=OneWay}" />
          <RadioButton Content="bluetooth" Grid.Column="1" HorizontalAlignment="Right"  Margin="0" IsChecked="{Binding UseBlueTooth, Mode=TwoWay}" IsEnabled="{Binding CanInitiateConnect, Mode=OneWay}" />
          <CheckBox Content="to wp8" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Margin="0,0,20,0" IsChecked="{Binding ConnectCrossPlatform, Mode=TwoWay}" IsEnabled="{Binding CanInitiateConnect, Mode=OneWay}" />

        </Grid>
        <ListBox Grid.Row ="0" ItemsSource="{Binding ConnectMessages}" Background="#FF091630" Foreground="White" Style="{StaticResource MyListboxStyle}"/>
        <Grid x:Name="bluetoothconnectgrid" VerticalAlignment="Bottom">
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
          </Grid.RowDefinitions>
          <interactivity:Interaction.Behaviors>
            <behaviors:HideWhenCollectionEmptyBehavior Collection="{Binding Peers}"/>
          </interactivity:Interaction.Behaviors>
          <ComboBox x:Name="OpponentsBox" HorizontalAlignment="Center" VerticalAlignment="Top"  ItemsSource="{Binding Peers}" SelectedItem="{Binding SelectedPeer, Mode=TwoWay}" Width="400" ItemTemplate="{StaticResource NormalContactTemplate}"/>
          <Button Content="select contact" Height="72" Grid.Row="1" Command="{Binding ConnectBluetoothContactCommand, Mode=OneWay}" HorizontalAlignment="Center"/>
        </Grid>
      </Grid>

      <!-- Message panel-->
      <Grid x:Name="MessageGrid" Visibility="{Binding CanSend, Converter={StaticResource VisibilityConverter}}"  >
        <Grid.RowDefinitions>
          <RowDefinition Height="110*"/>
          <RowDefinition Height="100*"/>
          <RowDefinition Height="412*"/>
        </Grid.RowDefinitions>
        <TextBox Height="72" Margin="0,10,0,0" TextWrapping="Wrap" VerticalAlignment="Center" Text="{Binding Message, Mode=TwoWay}"/>
        <Button Content="send message" Grid.Row="1" Command="{Binding SendComand, Mode=OneWay}"/>
        <ListBox Grid.Row="2" ItemsSource="{Binding ReceivedMessages}" Background="#FF091630" Foreground="White" Margin="12,0" Style="{StaticResource MyListboxStyle}"/>
      </Grid>
    </Grid>
  </Grid>
</Page>
